﻿using lBll;
using lDal;
using Model;

namespace BLL
{
    public class MemBerBll : lMemBerBll
    {
        public MemBerBll(lCaseDal<Certyeoy> dal, lCaseDal<CaiXia> dal1)
        {
            Dal = dal;
            Dal1 = dal1;
        }

        public lCaseDal<Certyeoy> Dal { get; }
        public lCaseDal<CaiXia> Dal1 { get; }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="certyeoy">表名</param>
        /// <returns>返回受影响行数</returns>
        public Task<int> Add(Certyeoy certyeoy)
        {
            return Dal.AddAsync(certyeoy);
        }

        /// <summary>
        /// 显示
        /// </summary>
        /// <param name="cname">食谱标题模糊查询</param>
        /// <param name="typeind">分类下拉精确查询</param>
        /// <returns></returns>
        public dynamic Show(string? cname, int? typeind)
        {
            var m = Dal.GetList();
            var types = Dal1.GetList();
            var query = from a in m
                        join b in types
                        on a.Typeid equals b.Tid
                        select new
                        {
                            a.Id,
                            a.Cainame,
                            a.Img, 
                            a.CBiqan,
                            a.Typeid,
                            a.CsDate,
                            a.CMeaages,
                            b.Tid,
                            b.Tname,
                        };
            if (!string.IsNullOrEmpty(cname))
            {
                query = query.Where(x => x.Cainame.Contains(cname));
            }
            if (typeind > 0)
            {
                query = query.Where(x => x.Typeid == typeind);
            }
            return query;
        }

        /// <summary>
        /// 下拉分类
        /// </summary>
        /// <returns>返回受影响行数</returns>
        public dynamic Xia()
        {
            return Dal1.GetList();
        }
    }
}
